# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgbase=fcitx5-pinyin-zhwiki
pkgname=(fcitx5-pinyin-zhwiki rime-pinyin-zhwiki)
_converterver=0.2.4
_zhwikiver=20230320
_webslangver=20230329
pkgver=$_converterver.$_webslangver
pkgrel=1
epoch=1
pkgdesc="Fcitx 5 Pinyin Dictionary from zh.wikipedia.org"
arch=('any')
url="https://github.com/felixonmars/fcitx5-pinyin-zhwiki"
license=('CCPL:by-sa' 'custom:GFDL')
makedepends=('libime' 'opencc' 'pypinyin')
source=(https://github.com/felixonmars/fcitx5-pinyin-zhwiki/archive/$_converterver/$pkgbase-$_converterver.tar.gz
        https://github.com/felixonmars/fcitx5-pinyin-zhwiki/releases/download/$_converterver/web-slang-$_webslangver.source
        https://dumps.wikimedia.org/zhwiki/$_zhwikiver/zhwiki-$_zhwikiver-all-titles-in-ns0.gz
        https://www.gnu.org/licenses/fdl-1.3.txt)
sha512sums=('f03215f0c6e137238a8c9f0ba557bf933ca2d4faf8c2a3aaa84f5e58485c8e0ace57f24d0cd855aa7a1d7e3001b4b36427c9a47ad04b92d11847bb5dbd24a709'
            '899aeba294c5235af94e45bc779d74879423c716e7c22aebe837c93542bd54c0d9281c0bafdbb086af7940e4410fd58be5aa0c534a1f7668dcf03efdb9c3a94a'
            'b2c05696aa3222b8c7ab5a6753cfa00388268f0daf91fb9838b560c599e1b7c1df257db59da5d4b12a58e6ffb062a568de43c7fa774493b1a964370f80431f67'
            '22d46818d3998ad841f537af4de7c50440dd918099fb6c5d4ab324cd71dc03066bfe1b67210a5efde77abd1d97b88da3c3dbfc39a24ae7248ee2d64e7f0fe6bb')

_make="make -L VERSION=$_zhwikiver WEB_SLANG_VERSION=$_webslangver"

prepare() {
  cd $pkgbase-$_converterver
  # Workaround pacman decompression
  touch zhwiki-$_zhwikiver-all-titles-in-ns0.gz
  ln -s ../zhwiki-$_zhwikiver-all-titles-in-ns0
  ln -s ../web-slang-$_webslangver.source
}

build() {
  cd $pkgbase-$_converterver
  $_make zhwiki.dict zhwiki.dict.yaml
}

package_fcitx5-pinyin-zhwiki() {
  cd $pkgbase-$_converterver
  $_make DESTDIR="$pkgdir" install
  install -Dm644 ../fdl-1.3.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}

package_rime-pinyin-zhwiki() {
  cd $pkgbase-$_converterver
  $_make DESTDIR="$pkgdir" install_rime_dict
  install -Dm644 ../fdl-1.3.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
